#include <iostream>
#include <cstring>
using namespace std;

class CTelNumber
{
private:
    char *cp;

public:
    CTelNumber(const char *number);
    ~CTelNumber();
    void print();
    CTelNumber(const CTelNumber &);
};

CTelNumber::CTelNumber(const char *number)
{
    cp = new char[strlen(number) + 1];
    strcpy(cp, number);
}

CTelNumber::~CTelNumber()
{
    delete[] cp;
}

void CTelNumber::print()
{
    cout << cp << endl;
}

CTelNumber::CTelNumber(const CTelNumber &ctn)
{
    cp = new char[strlen(ctn.cp) + 2];
    if (ctn.cp[0] >= '2' && ctn.cp[0] <= '4')
        cp[0] = '8';
    else if (ctn.cp[0] >= '5' && ctn.cp[0] <= '8')
        cp[0] = '2';
    strcpy(cp + 1, ctn.cp);
}

int judge(char *num)
{
    if (strlen(num) != 7)
        return 0;
    int i = 0;
    if (num[i] < '2' || num[i] > '8')
        return 0;
    ++i;
    while (num[i] != '\0')
    {
        if (num[i] < '0' || num[i] > '9')
            return 0;
        ++i;
    }
    return 1;
}

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        char telnumber[10];
        cin >> telnumber;
        if (judge(telnumber))
        {
            CTelNumber ct1(telnumber);
            CTelNumber ct2(ct1);
            ct2.print();
        }
        else
        {
            cout << "Illegal phone number" << endl;
        }
    }
}
